#ifndef PHYSICALLINKMANAGER_H
#define PHYSICALLINKMANAGER_H

/**
 * @copyright Copyright (c) 2025 
 * CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author zhouyan
*/
#include "sys_inc.h"
#include "phylink.h"

typedef struct ConfigSettings {
    uint32_t Realdata_Reportperiod;             //实时数据上报周期,单位秒
    uint32_t OfflineState_Reportperiod;         //传感器离线状态上报周期,单位秒
    uint32_t OnlineState_Reportperiod;          //传感器上线状态上报周期,单位秒
} ConfigSetting;


class PhysicalLinkManager
{
    typedef std::vector<ComSettings *>Settings;
    typedef std::vector<IPhyLink*> IPhyLinks;
public:
    ~PhysicalLinkManager();

    static PhysicalLinkManager * mgr();

    bool createCom(void);
    std::map<std::string, std::string>& getRemapCom(void);
    bool loadCom(void);
    bool loadConfig(void);
    void updateRemapCom();

    uint32_t devNum(void) const;
    IPhyLink *getDevice(uint32_t index, bool create = true);
    int devIndex(const char *dev_name) const;
    int portIndex(const char *dev_name) const;
    int getIndexByPort(const char *port) const {
        return devIndex(getDeviceName(port));
    }

    const char *devName(uint32_t index) const;
    const char *getPortName(uint32_t index) const {
        return getPortName(devName(index));
    }

    bool setDumpFlag(uint32_t index, bool enable);
    bool enableDump(uint32_t index) const;

    const char * getPortName(const char *dev_name) const;
    const char * getPortName(const std::string &dev_name) const {
        return getPortName(dev_name.c_str());
    }

    const char *getDeviceName(const char *port) const;
    const char *getDeviceName(const std::string &port) const {
        return getDeviceName(port.c_str());
    }

protected:
    PhysicalLinkManager();

private:
    IPhyLinks phy_devs_;
    Settings  settings_;
    std::map<std::string, std::string> coms_;
};

extern ConfigSetting g_config;

#endif // PHYSICALLINKMANAGER_H
